from __future__ import unicode_literals

from django.db import models

# Create your models here.
from django.utils.encoding import python_2_unicode_compatible
import datetime
from django.utils import timezone


class MarketManager(models.Manager):
    def create_market(self, market_name):
        market = self.get_or_create(market_name=market_name)
        return market


@python_2_unicode_compatible  # only if you need to support Python 2
class Market(models.Model):
    def __str__(self):
        return self.market_name
    market_name = models.CharField(max_length=200,unique=True)
    objects = MarketManager()


class FoodManager(models.Manager):
    def create_food(self, food_name):
        food = self.get_or_create(food_name=food_name)
        return food

@python_2_unicode_compatible  # only if you need to support Python 2
class Food(models.Model):
    def __str__(self):
        return self.food_name
    food_name = models.CharField(max_length=200,unique=True)
    objects = FoodManager()


class PageManager(models.Manager):
    def create_page(self, page_id, page_date):
        page = self.get_or_create(page_id=page_id,page_date=page_date)
        return page


@python_2_unicode_compatible  # only if you need to support Python 2
class Page(models.Model):
    def __str__(self):
        return self.page_id
    page_id = models.CharField(max_length=200,unique=True)
    page_date = models.DateField('date of buying')
    page_ok = models.BooleanField(default=True)
    objects = PageManager()

@python_2_unicode_compatible  # only if you need to support Python 2
class Price(models.Model):
    def __str__(self):
        return self.food.food_name
    market = models.ForeignKey(Market, on_delete=models.CASCADE)
    food = models.ForeignKey(Food, on_delete=models.CASCADE)
    price = models.DecimalField(max_digits=12, decimal_places=2, null=True)
    page = models.ForeignKey(Page,on_delete=models.CASCADE)


@python_2_unicode_compatible  # only if you need to support Python 2
class Err_price(models.Model):
    def __str__(self):
        return self.food.food_name
    market = models.ForeignKey(Market, on_delete=models.CASCADE)
    food = models.ForeignKey(Food, on_delete=models.CASCADE)
    price = models.CharField(max_length=200)
    page = models.ForeignKey(Page,on_delete=models.CASCADE)